<%@page import="com.net.test.vo.PageInfoVO"%>
<%@ page language="java" contentType="text/html; CHARSET=KSC5601" pageEncoding="UTF-8"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 <%--<%@ page language="java" contentType="application/vnd.ms-excel;charset=UTF-8" pageEncoding="UTF-8"%>--%>
<%@ page session="false" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.net.test.vo.TVO" %>


<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

<script>
function go_write(){
	var frm = document.writeFrm;	
	frm.action="/tWrite.ncb";
	frm.submit();
}
function go_logout(){
	var frm = document.writeFrm;
	frm.action="/tLogout.ncb";
	frm.submit();
}
function go_view(seq){
	var frm = document.writeFrm; 
	frm.seq.value = seq;
	
	frm.action="/tboardView.ncb";
	frm.submit();	
	
}
//검색
function searchFrm(){
	var frm = document.writeFrm;
	
	frm.action="/tlogView.ncb";
	frm.submit();
}
function go_edit(){
	var frm = document.writeFrm;
	
	frm.action="/tmemEdit.ncb";
	frm.submit();
}
function go_exceldown(){
	var frm = document.writeFrm;	
	frm.action="/exceldown.ncb";    
    frm.submit();	
}
function go_paging(page){
	var frm = document.writeFrm;
	frm.pageno.value = page;
// 	frm.action="/tlogView.ncb";
// 	frm.submit();
	
	var serial = $('form[name=writeFrm]').serialize();

	$.ajax({
		url : "/tlogView.ncb",
		async : false,
		type : "post",
		data : serial,
		success : function(msg, textStatus) {
			var html = $(msg).find("body").children().clone();
			$( "body" ).html(msg);
		},
		error : function(request, status, error) {
			alert("error : " + status);
		},
		beforeSend : function()/*submit 하기직전에*/ {
		}
	});

}
</script>

 <%
 	HttpSession session = request.getSession();
 	String login_id = (String)session.getAttribute("login_id");
 	String login_name = (String)session.getAttribute("login_name");
 	out.print(login_id+" "+login_name);

 	ArrayList<TVO> list = (ArrayList<TVO>)request.getAttribute("list"); 
	PageInfoVO pageInfoVO = (PageInfoVO)request.getAttribute("pageInfoVO");
	TVO tvo = (TVO)request.getAttribute("tvo");
	
	String searchKey = "";
	String searchVal = "";
	
	if(tvo != null){
		searchKey = tvo.getSearchKey() == null ? "" : tvo.getSearchKey();
		searchVal = tvo.getSearchVal() == null ? "" : tvo.getSearchVal();
	}
	
	
 %>

<br />
<h1>로그인되었습니다</h1> 
<br />

<form name="writeFrm" method="POST" >
		
	<input type="hidden" name="pageno" value="<%=pageInfoVO.getPageno() %>">
	<input type="hidden" name="seq">
	
    <br>
	<br>
	<br>
	<br>

			<select name="searchKey">
			<option value="제목" <%if(searchKey.equals("제목")){ out.print("selected='selected'"); } %>>제목</option>
			<option value="내용" <%if(searchKey.equals("내용")){ out.print("selected='selected'"); } %>>내용</option>
			</select>
			
			<input type="text" name="searchVal" value="<%=searchVal%>"/>
			<input type="button" value="검색" onclick="javascript: searchFrm();">
			
			<table width="90%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse; border:1px gray solid;">
			
        <tr>            
            <td width="10%" align="center">번호</td>
            <td width="30%" align="center">제목</td>
            <td width="50%" align="center">내용</td>
            <td width="50%" align="center">조회수</td>
            <td width="50%" align="center">추천수</td>
            
        </tr>
        
      
    
       
        <%
        if(list != null){
        	
	        for(int i = 0; i<list.size(); i++){ 
	        	
	        	TVO vo= (TVO)list.get(i);
	        %> 
	        <tr>
	            <td width="10%" align="center" > <%=vo.getRownum() %> </td>
	            <td width="30%" align="center" onclick="javascript:go_view('<%=vo.getSeq() %>')" > <%=vo.getTitle()%></td>
	            <td width="50%" align="center" onclick="javascript:go_view('<%=vo.getSeq() %>')"><%=vo.getContents() %></td>
	            <td width="50%" align="center" ><%=vo.getHit_count() %></td>
	            <td width="50%" align="center" ><%=vo.getLike_count() %></td>
	        </tr>
	        <%
	        }
        }
        %>
      
	  
    </table>   
		
	<input type="button" value="글쓰기" onclick="javascript:go_write('<%=login_id %>','<%=login_name %>','');"/>	
	<input type="button" value="회원정보수정" onclick="javascript:go_edit('<%=login_id %>','<%=login_name %>','');" />
	<input type="button" value="로그아웃" onclick="javascript:go_logout();" />
	<input type="button" value="목록보기" onclick="javascript:location.href='/tlogView.ncb'"/>
	<input type="button" value="엑셀 저장" onclick="javascript:go_exceldown();">
	 
	<br /><br /><br />	
</form>


<%
if(pageInfoVO !=null){
%>
<a href="javascript: go_paging('1')">[맨앞으로]</a>
<a href="javascript:go_paging('<%=pageInfoVO.getPrev_pageno()%>')">[이전]</a> 


<%for(int i = pageInfoVO.getPage_sno(); i<=pageInfoVO.getPage_eno(); i++){%>
	<a href="javascript: go_paging('<%=i %>')">
		<%if(pageInfoVO.getPageno() == i){ %>
			[<%=i%>]
		<%}else{ %>
			<%=i %>
		<%} %>
	</a> 
<%--	콤마	 --%>	
	<%if(i<pageInfoVO.getPage_eno()){ %>
		,
	<%} %>
<%} %>
 
<a href="javascript: go_paging('<%=pageInfoVO.getNext_pageno()%>')" >[다음]</a>
<a href="javascript: go_paging('<%=pageInfoVO.getTotal_page() %>')">[맨뒤로]</a>
<%} %>



